﻿<!DOCTYPE html>
<html  lang="en">
<head>
	<meta charset="UTF-8" />
<title>添加用户</title>
<link rel="stylesheet" type="text/css" href="/resource/css/css.css" />
<script type="text/javascript" src="/resource/js/jquery.min.js"></script>
<script type="text/javascript" src="/resource/js/public.js"></script>
<script type="text/javascript" src="/resource/js/jquery.cookie.js"></script>
<script type="text/javascript" src="/resource/js/contr.js"></script>
</head>
<body>

	<div id="pageAll">
		<div class="pageTop">
			<div class="page">
				<img src="/resource/img/coin02.png" />
				<span>
					<a href="#">首页</a>&nbsp;-&nbsp;
					<a href="#">用户管理</a>
				&nbsp;-</span>&nbsp;添加用户
			</div>
		</div>
		<div class="page ">			
			<div class="banneradd bor">
				<div class="baTopNo">
					<span>添加用户</span>
				</div>
				<div class="baBody">
					<span style="margin-left: 30px">0为管理员1为普通用户!</span>
					<div class="bbD">
						&nbsp;&nbsp;&nbsp;用户名：<input type="text" class="input3" id="username" />
					</div>
					<div class="bbD">
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;密码：<input type="password" class="input3" id="password" />
					</div>
					<div class="bbD">
						确认密码：<input type="password" class="input3"  id="checkpass" />
					</div>
					<div class="bbD">
						用户等级：<input type="text" class="input3" id="level" value="1" />
					</div><div class="bbD">
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;密钥：<input type="text" class="input3" id="key" value="<?php echo $key ?>" />	
					</div>
					<div class="bbD">
						<p class="bbDP">
							<button class="btn_ok btn_yes" href="javascript:void(0)" id="btn">提交</button>
							<a class="btn_ok btn_no" href="?c=admin&m=main" target="_self" id="connel">取消</a>
						</p>
					</div>
				</div>
			</div>

		</div>
	</div>
</body>
<script type="text/javascript">
	$(document).ready(function(){
		if (window.top==window.self){  
		   window.top.location="?c=admin&m=index"; 
		}
		
	});

	$("#btn").click(function(){
		var username = $("#username").val();
		var password = $("#password").val(); 
		var checkpass = $("#checkpass").val(); 
		var level  = $("#level").val();
		var key = $("#key").val();
		if(username=='' || password=='' || password=='' || checkpass==''){
			alert("用户名或密码不能为空!");
			return false;
		}
		if(password!=checkpass){
			alert("两次输入密码不一致!");
			return false;
		}
			$.ajax({
			"url":"?c=user&m=useradd",
			"dataType":"json",
			"data":{"username":username,"password":password,"level":level,"key":key},
			"type":"post",
			success:function(re){
				if(re.code=='0'){	
					alert("添加用户成功!");
					window.location.reload();
				}else if(re.code=='110'){
					alert("用户名已存在!");
				}else{
					alert('添加用户失败!');
				}
			}
			});
	});

	function createKey(){
		
		$.ajax({
		"url":"?c=user&m=createKey",
		"dataType":"json",
		"data":{"password":password},
		"type":"post",
		success:function(re){
			if(re.code=='0'){	
				 $("#key").val(re.key);
			}else{
				alert('密码不正确!');
			}
		}
		});
	}
</script>
</html>